package hn.cch.web.request.controller;


import hn.cch.web.request.entity.AttributeModel;
import hn.cch.web.request.entity.ParameterModel;
import hn.cch.web.request.property.CustomExampleEditor;
import hn.cch.web.request.property.CustomExampleEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static hn.cch.web.request.validate.ValidateUtil.handleValidate;

@RequestMapping(value = "/request")
@RestController()
public class RequestController {

    private static final Logger logger = LoggerFactory.getLogger(RequestController.class);


    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public ResponseEntity<String> get() {
        logger.info("get");
        return ResponseEntity.ok("OK");
    }

    @RequestMapping(value = "/post", method = RequestMethod.POST)
    public ResponseEntity<String> post(@RequestBody @Validated ParameterModel entity, BindingResult result) {
        logger.info("post");
        if (result.hasErrors()) {
            return handleValidate(result);
        }
        return ResponseEntity.ok("OK");
    }

    @RequestMapping(value = "/setAttributeModel", method = RequestMethod.POST)
    public ResponseEntity<String> setAttributeModel(@ModelAttribute("attributeModel") AttributeModel attributeModel) {
        logger.info("setAttributeModel");
        return ResponseEntity.ok("OK");
    }


}
